import { fromLonLat } from 'ol/proj';

export default class TrajectoryLoader {

    // 加载 CSV 数据
    async loadCSV(url: string) {
        try {
            const response = await fetch(url);
            const arrayBuffer = await response.arrayBuffer();
            const decoder = new TextDecoder('utf-8'); // 指定编码
            const text = decoder.decode(arrayBuffer);
            const filteredLines = text.trim().split('\n');
            const lines = filteredLines.slice(3, -1);
            let coordinates: Array<any> = []
            lines.forEach(line => {
                const objLine = line.split(',');
                const path = [Number(objLine[4]), Number(objLine[5])]
                coordinates.push({
                    time: new Date(objLine[2] + " " + objLine[3]).getTime(),
                    name: '',
                    coordinates: path,
                    heading:objLine[8]
                });
            });

            return coordinates
        } catch (error) {
            console.error('Error loading CSV:', error);
        }
    }

    

}
